package CartService

import (
	"context"
	"gdshop-back-end-go/client-api/app/request/CartReq"
	toolsDb "gdshop-back-end-go/common/db"
	"gdshop-back-end-go/common/response"
	"gdshop-back-end-go/service-member/CartService"
	"github.com/gogf/gf/frame/g"
)

func SelectedAll(ctx context.Context, parames *CartReq.SelectedAll) *response.JsonResponse {
	_, err := toolsDb.GetUnSafaTableAddDeleteWhere(ctx, "member_cart").Where(
		"member_id=?",
		parames.MemberId,
	).Update(g.Map{
		"is_selected": getIsSelectedValue(parames.IsSelected),
	})
	if err != nil {
		return response.FailByRequestMessage(nil, err.Error())
	} else {
		return response.SuccessByRequestMessageData(nil, "成功",
			CartService.BaseCount(ctx, parames.MemberId))
	}
}
